package com.gavindon.android.utils

import android.app.Activity
import android.content.Context
import android.content.Intent
import android.content.res.Resources
import android.view.View
import com.gavindon.android.HomeActivity
import com.gavindon.android.base.INTENT_COURSE_ID
import com.gavindon.android.base.INTENT_COURSE_NAME
import com.gavindon.android.entity.LoginStatus
import com.gavindon.android.view.combo.ComboLstActivity
import com.gavindon.android.view.start.LoginActivity
import com.gavindon.android.view.video.VideoActivity
import com.gavindon.android.view.video.VideoDetailActivity
import org.jetbrains.anko.startActivity
import org.jetbrains.anko.startActivityForResult
import org.jetbrains.anko.toast

/**
 * description:
 * Created by liNan on  2022-2-11 00:03
 */

fun View.click(block: () -> Unit) {
    this.setOnClickListener {
        if (LoginStatus.hasLogin) {
            block.invoke()
        } else {
            context.toast("请先登录")
            this.context.startActivity<LoginActivity>()
        }
    }
}

//免费可跳转视频页面
fun View.clickFree(block: () -> Unit) {
    this.setOnClickListener {
        block.invoke()
    }
}

const val requestLoginCode: Int = 100
fun Activity.clickForResult(view: View, block: (() -> Unit)? = null) {
    view.setOnClickListener {
        if (LoginStatus.hasLogin) {
            block?.invoke()
        } else {
            view.context.toast("请先登录")
            this.startActivityForResult<LoginActivity>(requestLoginCode)
        }
    }
}


/**
 * 是否是短视频 subjectType区分短视频1/正常课程0两种类型，
 * 跳转全屏播放视频或者详情页面
 */
fun Context.toFullVideoOrDetailPage(subjectType: Int, courseId: String, courseName: String) {
//    this.startActivity<ComboLstActivity>()


    if (subjectType == 1) {
        this.startActivity<VideoActivity>(
            Pair(INTENT_COURSE_NAME, courseName),
            Pair(INTENT_COURSE_ID, courseId)
        )
    } else {
        this.startActivity<VideoDetailActivity>(
            Pair(INTENT_COURSE_NAME, courseName),
            Pair(INTENT_COURSE_ID, courseId)
        )
    }

}

fun String.ymd(): String {
    return when (this) {
        "year" -> "年"
        "month" -> "月"
        "day" -> "天"
        else -> {
            ""
        }
    }
}

val phoneWidth: Int
    get() = Resources.getSystem().displayMetrics.widthPixels
val phoneHeight: Int
    get() = Resources.getSystem().displayMetrics.heightPixels

fun Context.mToast() {
    this.toast("暂未开放")
}

//课程是免费/收费  课程和章节相反
enum class FreeStatus {
    NEED_PAY,
    FREE,
}

enum class CourseFreeStatus {
    FREE,
    NEED_PAY,
}

enum class PayStatus {

}
